package leetcode;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;

/**
 * 描述:513. 找树左下角的值
 *
 * @author Madison You
 * @created 2:01
 */
public class Mid_513_FindBottomLeftValue {
    public static void main(String[] args) {
        Integer[] integers = {2, 1, 3};
        TreeNode treeNode = CreateTreeNode.arrayToTreeNode(integers);
        new Mid_513_FindBottomLeftValue().findBottomLeftValue(treeNode);
    }

    public int findBottomLeftValue(TreeNode root) {
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        int tem = root.val;
        while (!queue.isEmpty()) {
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                TreeNode node = queue.poll();
                if (i == 0) {
                    tem = node.val;
                }
                if (node.left != null) queue.offer(node.left);
                if (node.right != null) queue.offer(node.right);
            }
        }
        return tem;
    }
}
